#include <string>
#include <iostream>

using namespace std;

class Solution {
public:
    int monotoneIncreasingDigits(int N) {
        string Nstr = std::to_string(N);
        int the_last_increasing_from_right = Nstr.size() - 1;
        for (int i = the_last_increasing_from_right - 1; i >= 0; i--) {
            if (Nstr[i] > Nstr[i+1]) {
                the_last_increasing_from_right = i;
                Nstr[i] -= 1;
            }
        }
        int len = Nstr.size();
        if (the_last_increasing_from_right == len) return N;
        for (int i = the_last_increasing_from_right + 1; i < len; i++) {
            Nstr[i] = '9';
        }
        
        return std::atoi(Nstr.c_str());
    }
};

int stringToInteger(string input) {
    return stoi(input);
}

int main() {
    string line;
    while (getline(cin, line)) {
        int N = stringToInteger(line);
        
        int ret = Solution().monotoneIncreasingDigits(N);

        string out = to_string(ret);
        cout << out << endl;
    }
    return 0;
}
